//
//  ViewController.swift
//  mySwift
//
//  Created by vincent on 9/25/14.
//  Copyright (c) 2014 vincent. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    var myView: UIView!
    
    var myButton: UIButton {
        get {
            return UIButton.buttonWithType(UIButtonType.Custom) as UIButton
        }
    }

    // MARK: - Lifecycle
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        title = "Title"
        myView = UIView(frame: CGRectMake(0, 0, 10, 80)) as UIView
        view.addSubview(myView)
        myView.backgroundColor = UIColor.greenColor()
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "didRotated:", name: UIDeviceOrientationDidChangeNotification, object: nil)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    // MARK: - Rotation
    
    override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
        println("iOS 8")
    }
    
    func didRotated(notification: NSNotification) {
        var orientaion: UIDeviceOrientation = UIDevice.currentDevice().orientation
        var userInfo = notification.userInfo
        var rect: CGRect = view.bounds
        var frameRect: CGRect = view.frame
        
        self.myView.frame = CGRectMake(0, 0, self.view.bounds.size.width-5, 80)
    }
}

